package main

import (
	"fmt"
	"iot-base/common/ctrltype"
	"iot-base/devc/common/loader"
	"strconv"
)

func registserve() {
	fmt.Println("----------regist------------")
	loader.SubCtrlHandler(func(pCmd *ctrltype.CtrlCmd) (map[string]interface{}, error) {
		fmt.Println("serve")
		switch pCmd.ID {
		case "pin":
			c, ok := pCmd.Params["card"].(string)
			if ok {
				tcard, _ := strconv.ParseInt(c, 10, 0)
				card = int(tcard)
				Order = sendCard
			} else {
				fmt.Println("type err!")
			}
		case "query":
			Order = queryCard
			res := <-queryres
			var resmap map[string]interface{}
			resmap = make(map[string]interface{})
			resmap["query msg"] = res
			return resmap, nil
		case "delete":
			c, ok := pCmd.Params["card"].(string)
			if ok {
				tcard, _ := strconv.ParseInt(c, 10, 0)
				card = int(tcard)
				Order = deleteCard
			} else {
				fmt.Println("type err!")
			}
		case "Open":
			Order = openDoor
		case "Close":
			Order = closeDoor
		}
		return nil, nil
	})
}
